package com.guigu.handler;

import com.guigu.exception.SsmException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * 自定义异常处理解析器
 * 统一异常处理
 * Spring AOP
 */
@ControllerAdvice
public class MyHandlerExceptionResolver1 {

    @ExceptionHandler(value = SsmException.class)
    public ModelAndView handleException(Exception exception) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("errorMessage", exception.getMessage());
        modelAndView.setViewName("error");
        return modelAndView;
    }
}
